package com.zkthink.ceres.store.controller;

import cn.hutool.extra.servlet.ServletUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zkthink.base.R;
import com.zkthink.base.controller.SuperController;
import com.zkthink.base.request.PageParams;
import com.zkthink.ceres.store.dto.StoreWithdrawHisPageDTO;
import com.zkthink.ceres.store.dto.StoreWithdrawHisSaveDTO;
import com.zkthink.ceres.store.dto.StoreWithdrawHisUpdateDTO;
import com.zkthink.ceres.store.entity.StoreWithdrawHis;
import com.zkthink.ceres.store.service.StoreWithdrawHisService;
import com.zkthink.context.BaseContextHandler;
import com.zkthink.security.annotation.PreAuth;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * <p>
 * 前端控制器
 * 店铺提现历史
 * </p>
 *
 * @author chenke
 * @date 2022-04-29
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/storeWithdrawHis")
@Api(value = "StoreWithdrawHis", tags = "店铺提现历史")
@PreAuth(replace = "storeWithdrawHis:")
public class StoreWithdrawHisController extends SuperController<StoreWithdrawHisService, Long, StoreWithdrawHis, StoreWithdrawHisPageDTO, StoreWithdrawHisSaveDTO, StoreWithdrawHisUpdateDTO> {

    @ApiOperation(value = "查询提现历史", notes = "查询提现历史")
    @PostMapping(value = "/findXsyWithdrawHis")
    public R<IPage<StoreWithdrawHis>> findXsyWithdrawHis(@RequestBody PageParams<StoreWithdrawHisPageDTO> dto) {
        StoreWithdrawHisPageDTO model = dto.getModel();
        IPage page = dto.getPage();
        return baseService.findXsyWithdrawHis(page, model);
    }


    @ApiOperation(value = "审核提现", notes = "审核提现")
    @PostMapping(value = "/adjustXsyWithdrawHis")
    public R adjustStoreXsyWithdrawHis(HttpServletRequest request, @RequestBody StoreWithdrawHisUpdateDTO dto) {
        Long userId = BaseContextHandler.getUserId();
        dto.setAdjustId(userId);
        String ip = ServletUtil.getClientIP(request);
        return baseService.adjustStoreXsyWithdrawHis(dto, ip);
    }











    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<StoreWithdrawHis> ceresStoreWithdrawHisList = list.stream().map((map) -> {
            StoreWithdrawHis ceresStoreWithdrawHis = StoreWithdrawHis.builder().build();
            //TODO 请在这里完成转换
            return ceresStoreWithdrawHis;
        }).collect(Collectors.toList());

        return R.success(baseService.saveBatch(ceresStoreWithdrawHisList));
    }
}
